/*
 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 * conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
 * of conditions and the following disclaimer in the documentation and/or other materials
 * provided with the distribution.
 *
 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
 * to endorse or promote products derived from this software without specific prior written
 * permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef _IT_POSIX_CONTAINER_H
#define _IT_POSIX_CONTAINER_H

#include "osTest.h"
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <regex>
#include <time.h>
#include <sys/syscall.h>
#include <sys/capability.h>
#include "sched.h"
#include "signal.h"
#include "semaphore.h"
#include "sched.h"
#include "pthread.h"
#include "limits.h"
#include "unistd.h"
#include "mqueue.h"
#include "signal.h"
#include "sys/time.h"
#include "sys/shm.h"
#include "sys/types.h"

#define CONTAINER_FIRST_PID 1
#define CONTAINER_SECOND_PID 2
#define CONTAINER_THIRD_PID 3
#define TEST_ERRNO_255 255
#define STACK_SIZE (1024 * 1024)

std::string gen_container_link_path(int pid, const std::string& containerType);

extern std::string readlink_container(int pid, const std::string& containerType);

int ChildFunction(void *args);

pid_t CloneWrapper(int (*func)(void *), int flag, void *args);

#if defined(LOSCFG_USER_TEST_SMOKE)

VOID ItPosixContainer001(VOID);
VOID ItPosixContainer001NET(VOID);
VOID ItPosixContainer001NS(VOID);
VOID ItPosixContainer001PID(VOID);
VOID ItPosixContainer001FLAGS(VOID);
#if defined(LOSCFG_USER_TEST_USER_CONTAINER)
void ItPosixContainer001USER(void);
#endif
#if defined(LOSCFG_USER_TEST_UTS_CONTAINER)
void ItPosixContainer001UTS(void);
#endif
VOID ItPosixContainer002(VOID);
VOID ItPosixContainer003(VOID);
VOID ItPosixContainer004(VOID);
#if defined(LOSCFG_USER_TEST_UTS_CONTAINER)
void ItPosixContainer006(void);
void ItPosixContainer007(void);
void ItPosixContainer008(void);
#endif
VOID ItPosixContainer009(VOID);
VOID ItPosixContainer010(VOID);
#if defined(LOSCFG_USER_TEST_USER_CONTAINER)
void ItPosixContainer011(void);
void ItPosixContainer012(void);
void ItPosixContainer013(void);
#endif
VOID ItPosixContainer014(VOID);
#if defined(LOSCFG_USER_TEST_MNT_CONTAINER)
VOID ItPosixContainerMnt001(VOID);
VOID ItPosixContainerMnt002(VOID);
VOID ItPosixContainerMnt003(VOID);
VOID ItPosixContainerMnt004(VOID);
VOID ItPosixContainerMnt005(VOID);
VOID ItPosixContainerMnt006(VOID);
VOID ItPosixContainerMnt007(VOID);
VOID ItPosixContainerMnt008(VOID);
#endif
#if defined(LOSCFG_USER_TEST_NET_CONTAINER)
VOID ItPosixContainerNet001(VOID);
VOID ItPosixContainerNet002(VOID);
VOID ItPosixContainerNet003(VOID);
VOID ItPosixContainerNet004(VOID);
VOID ItPosixContainerNet005(VOID);
VOID ItPosixContainerNet006(VOID);
VOID ItPosixContainerNet007(VOID);
VOID ItPosixContainerNet008(VOID);
VOID ItPosixContainerNet009(VOID);
#endif
VOID ItPosixPidContainer001(VOID);
VOID ItPosixPidContainer002(VOID);
VOID ItPosixPidContainer003(VOID);
VOID ItPosixPidContainer004(VOID);
VOID ItPosixPidContainer005(VOID);
VOID ItPosixPidContainer006(VOID);
VOID ItPosixPidContainer007(VOID);
VOID ItPosixPidContainer008(VOID);
VOID ItPosixPidContainer009(VOID);
VOID ItPosixPidContainer010(VOID);
VOID ItPosixPidContainer011(VOID);
VOID ItPosixPidContainer012(VOID);
VOID ItPosixPidContainer013(VOID);
VOID ItPosixPidContainer014(VOID);
VOID ItPosixPidContainer015(VOID);
VOID ItPosixPidContainer016(VOID);
VOID ItPosixPidContainer017(VOID);
VOID ItPosixPidContainer018(VOID);
VOID ItPosixPidContainer019(VOID);
VOID ItPosixPidContainer020(VOID);
VOID ItPosixPidContainer021(VOID);
VOID ItPosixPidContainer022(VOID);
#if defined(LOSCFG_USER_TEST_TIME_CONTAINER)
VOID ItPosixContainerTime001(VOID);
VOID ItPosixContainerTime002(VOID);
VOID ItPosixContainerTime003(VOID);
VOID ItPosixContainerTime004(VOID);
VOID ItPosixContainerTime005(VOID);
VOID ItPosixContainerTime006(VOID);
VOID ItPosixContainerTime007(VOID);
VOID ItPosixContainerTime008(VOID);
VOID ItPosixContainerTime009(VOID);
#endif
#if defined(LOSCFG_USER_TEST_IPC_CONTAINER)
VOID ItPosixContainerIpc001(VOID);
VOID ItPosixContainerIpcShmClone001(VOID);
VOID ItPosixContainerIpcShmUnshare001(VOID);
VOID ItPosixContainerIpcShmSetns001(VOID);
VOID ItPosixContainerIpcMq001(VOID);
VOID ItPosixContainerIpcMq002(VOID);
VOID ItPosixContainerIpcMq003(VOID);
#endif
#endif

#if defined(LOSCFG_USER_TEST_STABILITY)
#if defined(LOSCFG_USER_TEST_UTS_CONTAINER)
void ItPosixContainerStability001(void);
#endif
#if defined(LOSCFG_USER_TEST_USER_CONTAINER)
void ItPosixContainerStability002(void);
#endif
void ItPosixContainerStability003(void);
void ItPosixContainerStability004(void);
#if defined(LOSCFG_USER_TEST_PID_CONTAINER)
void ItPosixContainerStability005(void);
#endif
#endif

#endif /* _IT_POSIX_CONTAINER_H */
